package com.example.work1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    static String ac = "bianqiuyan";
    static String pd = "123456";
    //声明控件
    private Button login;
    private EditText account;
    private EditText psd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //找到控件
        account= (EditText) findViewById(R.id.e1);
        psd= (EditText) findViewById(R.id.e2);
        login=(Button)findViewById(R.id.login);
        //匹配到正确的用户名和密码进行登录操作
        login.setOnClickListener(this);


    }
    public void onClick(View v){

        //获取输入的用户名和密码
        String a=account.getText().toString();
        String p=psd.getText().toString();

        //弹出内容设置
        String ok = "登录成功";
        String fail = "账号或密码有误，请重新登录";

        //假设用户名：bianqiuyan密码为123456
        if (a.equals(ac)&&p.equals(pd)){
            //Toast 设置
            Toast.makeText(getApplicationContext(),ok,Toast.LENGTH_SHORT).show();

            //如果正确，进行跳转
            Intent intent = new Intent(MainActivity.this,MainActivity2.class);
            startActivity(intent);
        }else{//不正确弹出Toast登陆失败
            Toast toast = Toast.makeText(getApplicationContext(),fail,Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER,0,0);
            toast.show();

        }

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        super.onPointerCaptureChanged(hasCapture);
    }
}